POV-Ray : Newsgroups : povray.general : Re: Probably been asked... Why no power operator? : Re: Probably been asked... Why no power operator? Server Time
5 Aug 2024 12:17:21 EDT (-0400)
  Re: Probably been asked... Why no power operator?  
From: Slime
Date: 14 Nov 2002 11:11:40
Message: <3dd3cb3c$1@news.povray.org>
>   It's only consistent that the unary minus has higher precedence than the
> power operator as well, as it allows you to write "-2^3" and "2^-3".
There's
> no mathematical reason for making the unary minus to have a lower
precedence
> then the power operator.


Well, to say there's no mathematical reason doesn't seem entirely correct.
Most everyone is taught that exponentiation comes before negation in an
early algebra class. It's the way we've been taught to think.

I am of the opinion that sacrificing the strange 2^-3 syntax for 2^(-3)
makes more sense than having to use -(3^9) in place of -3^9. This is *sorta*
inconsistent with the way the * operator works, except that no one's going
to argue what the value of -2*2 is.

The thing is, you could say that the multiplication in -2*2 is done first,
and then the unary negation, and it wouldn't matter. So to then say that the
exponentiation is done first in -3^9 makes sense.

Besides, I would think that since we're adding ^ as a new operator, we could
give it whatever precedence we wanted, and it just seems more logical to me
to make it work the way we've been taught it should work than to allow the
2^-3 syntax just for convenience.

If the designers of POV-Ray really think that their implementation makes
more sense, than so be it. I'd rather they hadn't taken it out, even if it
*is* a little strange in certain cases. Besides, by taking it out, they
obviously haven't prevented arguments about it ;)

>   Of course all this hassle would have been avoided if you just had
silently
> used "-(2^3)" without complaining... We would still have the power
operator. ;)

Hah =) I know, sorry. I didn't see it as complaining at the time, though; I
thought it was a bug.

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.